import { createRouter, createWebHistory } from 'vue-router'

const routes = [{
        path: '/',
        name: '首页',
        component: () =>
            import ('../Layout/baseLayout.vue'),
        children: [{
                path: '/',
                name: '',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/index/index.vue'),
            },
            //学生路由
            {
                path: '/experiments',
                name: '未完成实验',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Experiments.vue'),
            },
            {
                path: '/doneexperiments',
                name: '已完成实验',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/DoneExperiments.vue'),
            },
            {
                path: '/passedexperiments',
                name: '已通过实验',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/PassedExperiments.vue'),
            },
            {
                path: '/examination-paper/1',
                name: '实验一',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp1.vue'),
            },
            {
                path: '/examination-paper/2',
                name: '实验二',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp2.vue'),
            },
            {
                path: '/examination-paper/3',
                name: '实验三',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp3.vue'),
            },
            {
                path: '/examination-paper/4',
                name: '实验四',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp4.vue'),
            },
            {
                path: '/examination-paper/9',
                name: '实验九',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp9.vue'),
            },
            {
                path: '/examination-paper/10',
                name: '实验十',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp10.vue'),
            },
            {
                path: '/examination-paper/15',
                name: '实验十五',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp15.vue'),
            },
            {
                path: '/examination-paper/16',
                name: '实验十六',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp16.vue'),
            },
            {
                path: '/examination-paper/17',
                name: '实验十七',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp17.vue'),
            },
            {
                path: '/examination-paper/19',
                name: '实验十九',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp19.vue'),
            },
            {
                path: '/examination-paper/6',
                name: '实验六',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp6.vue'),
            },
            {
                path: '/examination-paper/7',
                name: '实验七',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp7.vue'),
            },
            {
                path: '/examination-paper/11',
                name: '实验十一',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp11.vue'),
            },
            {
                path: '/examination-paper/12',
                name: '实验十二',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp12.vue'),
            },
            {
                path: '/examination-paper/14',
                name: '实验十四',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp14.vue'),
            },
            {
                path: '/examination-paper/18',
                name: '实验十八',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp18.vue'),
            },
            {
                path: '/examination-paper/20',
                name: '实验二十',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp20.vue'),
            },
            {
                path: '/examination-paper/27',
                name: '实验二十七',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Students/Exps/Exp27.vue'),
            },
            //老师路由
            {
                path: '/exp-manage/classLists',
                name: '实验管理',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ExpManage.vue'),
                children: [{
                        path: '/exp-manage/classLists',
                        meta: {
                            requireAuth: true,
                        },
                        component: () =>
                            import ('../views/Teachers/ClassList.vue'),
                    },
                    {
                        path: '/exp-manage/studentList',
                        meta: {
                            requireAuth: true,
                        },
                        component: () =>
                            import ('../views/Teachers/StudentList.vue'),
                    },
                ],
            },
            {
                path: '/review-exp',
                name: '待批阅实验',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewExp.vue'),
            },
            {
                path: '/test',
                name: '实验数据管理',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ExpManage.vue'),
                children: [{
                        path: '/test',

                        component: () =>
                            import ('../views/Teachers/ClassList.vue'),
                    },
                    {
                        path: '/exp-manage/studentList',

                        component: () =>
                            import ('../views/Teachers/StudentList.vue'),
                    },
                ],
            },
            {
                path: '/unreview-exp',
                name: '未批阅实验',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewExp.vue'),
            },
            {
                path: '/review-class/:id',
                name: '待批阅班级',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewClass.vue'),
            },
            {
                path: '/review-student/:id',
                name: '待批阅学生',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewStudent.vue'),
            },
            {
                path: '/unreview-student/:id',
                name: '未批阅学生',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/UnReviewStudent.vue'),
            },
            {
                path: '/review-paper/1',
                name: '批阅试卷1',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp1.vue'),
            },
            {
                path: '/review-paper/2',
                name: '批阅试卷2',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp2.vue'),
            },
            {
                path: '/review-paper/3',
                name: '批阅试卷3',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp3.vue'),
            },
            {
                path: '/review-paper/4',
                name: '批阅试卷4',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp4.vue'),
            },
            {
                path: '/review-paper/9',
                name: '批阅试卷9',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp9.vue'),
            },
            {
                path: '/review-paper/10',
                name: '批阅试卷10',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp10.vue'),
            },
            {
                path: '/review-paper/15',
                name: '批阅试卷15',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp15.vue'),
            },
            {
                path: '/review-paper/16',
                name: '批阅试卷16',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp16.vue'),
            },
            {
                path: '/review-paper/17',
                name: '批阅试卷17',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp17.vue'),
            },
            {
                path: '/review-paper/19',
                name: '批阅试卷19',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Teachers/ReviewPapers/Exp19.vue'),
            },
            //管理员路由
            {
                path: '/root/expmanage',
                name: '实验管理',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Root/ExpManage.vue'),
            },
            {
                path: '/root/classlist',
                name: '班级列表',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Root/ClassList.vue'),
            },
            {
                path: '/root/teachermanage',
                name: '教师管理',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Root/TeacherManage.vue'),
            },
            {
                path: '/root/semester',
                name: '学期管理',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Root/SemesterManage.vue'),
            },
            //下面是个人中心
            {
                path: '/teacherpersonal',
                name: '教师个人中心',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Personal/TP.vue'),
                //教师个人中心
            },
            {
                path: '/studentpersonal',
                name: '学生个人中心',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Personal/SP.vue'),
                //学生个人中心
            },
            {
                path: '/rootpersonal',
                name: '管理员个人中心',
                meta: {
                    requireAuth: true,
                },
                component: () =>
                    import ('../views/Personal/RP.vue'),
                //管理员个人中心
            },
        ],
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ('../views/Login/Login.vue'),
    },

    {
        path: '/:catchAll(.*)',
        name: '404',
        component: () =>
            import ('../views/404/404.vue'),
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

//全局开启路由守卫，检验cookie
router.beforeEach((to, from, next) => {
    //跳转到登录页
    if (to.path === '/login') {
        next()
    } else {
        // 检查权限路由
        if (to.meta.requireAuth) {
            // 检查cookie
            // if (document.cookie.indexOf('ticket') === -1) {
            const user = JSON.parse(sessionStorage.getItem('user') || '{}')
            console.log(user)

            if (user.IsLogin === null) {
                ElMessage.error('请登录')
                next('/login')
            } else {
                next()
            }
        }
    }
})
export default router